<?php

namespace app\admin\model\advertiser;

use aliyun\AliyunOss;
use app\BaseModel;

/**
 * 广告主页面广告位推广物表
 */
class AdvertiserPage extends BaseModel
{

    /**
     * 获取页面广告位列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = ''): array
    {
        $data = self::where($where)
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        $AliyunOss = new AliyunOss();
        //遍历数组
        foreach ($data['data'] as $k => &$v) {
            $v['example_url'] = $AliyunOss->getObjectUrl($v['example']);
            $v['device_type_arr'] = json_decode($v['device_type'], true);
        }
        return $data;
    }

    /**
     * 获取全部页面广告位列表
     * @param array $where
     * @param string $orderby
     * @return array
     */
    public static function getListAll(array $where, string $orderby = ''): array
    {
        $data = self::field('id,code,name,pictures,example,desc')
            ->where($where)
            ->order($orderby)
            ->select()
            ->toArray();
        $AliyunOss = new AliyunOss();
        //遍历数组
        foreach ($data as &$v) {
            $v['example_url'] = $AliyunOss->getObjectUrl($v['example']);
        }
        return $data;
    }

}